﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using vJine.Core;

namespace vJine.Lua.GUI {
    /// <summary>
    /// WinFlowChart.xaml 的交互逻辑
    /// </summary>
    public partial class WinFlow : Window {

        public WinFlow() {
            InitializeComponent();

            this.btnCmdA_TOP.Command = this.drc;
            this.btnCmdA_TOP.CommandParameter = "CMD_ALIGN_TOP";
            this.btnCmdA_BOTTOM.Command = this.drc;
            this.btnCmdA_BOTTOM.CommandParameter = "CMD_ALIGN_BOTTOM";
            this.btnCmdA_VCENTER.Command = this.drc;
            this.btnCmdA_VCENTER.CommandParameter = "CMD_ALIGN_VCENTER";
            this.btnCmdA_LEFT.Command = this.drc;
            this.btnCmdA_LEFT.CommandParameter = "CMD_ALIGN_LEFT";
            this.btnCmdA_RIGHT.Command = this.drc;
            this.btnCmdA_RIGHT.CommandParameter = "CMD_ALIGN_RIGHT";
            this.btnCmdA_HCENTER.Command = this.drc;
            this.btnCmdA_HCENTER.CommandParameter = "CMD_ALIGN_HCENTER";

            this.btnCmd_Save.Command = this.drc;
            this.btnCmd_Save.CommandParameter = "CMD_SAVE";
            this.btnCmd_Load.Command = this.drc;
            this.btnCmd_Load.CommandParameter = "CMD_LOAD";

            this.btnCmd_Run.Command = this.drc;
            this.btnCmd_Run.CommandParameter = "CMD_RUN";

            this.drc.winMain = this;
        }

        private void Label_MouseDown(object sender, MouseButtonEventArgs e) {
            NodeConfig nConfig = this.trvConfigs.SelectedItem as NodeConfig;
            if (nConfig == null || nConfig.ignore) {
                return;
            }

            this.drc.doDrag(nConfig);
        }

        private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
            NodeConfig nConfig = this.trvConfigs.SelectedItem as NodeConfig;
            if (nConfig == null || nConfig.ignore) {
                return;
            }
            e.Handled = true;

            WinOptions.ShowOptions(this.luaContext, nConfig);
        }

        LuaContext luaContext;
        NodeConfig luaConfig;

        public WinFlow set_bound(LuaContext luaContext, NodeConfig luaConfig) {
            this.luaContext = luaContext;
            this.luaConfig = luaConfig;

            this.drc.luaContext = luaContext;
            this.drc.nodeConfigs = luaConfig;
            this.drc.set_context();

            this.trvConfigs.Items.Clear();
            this.trvConfigs.ItemsSource = this.luaConfig;

            return this;
        }
    }
}
